<?php
	session_start();
	include_once("connect.php");
	mysql_select_db("progin_171_13509047",$con);
	
	if (isset($_SESSION["userid"]))
	{
		 
		if (!headers_sent())
			 header('Location : index.php');
		else
			echo htmlspecialchars(SID);
		
	}
	else
	{
			function parseErrorMessage($error)
			{
				switch($error)
				{
					case 1 : echo "*username kurang dari 5 karakter";break;
					case 2 : echo "*password kurang dari 8 karakter";break;
					case 3 : echo "*username tidak boleh sama dengan password";break;
					case 4 : echo "*password tidak boleh sama dengan email";break;
					case 5 : echo "*konfirmasi password tidak cocok";break;
					case 6 : echo "*nama lengkap tidak valid";break;
					case 7 : echo "*tanggal lahir tidak valid";break;
					case 8 : echo "*email tidak valid";break;
					case 9 : echo "*avatar tidak valid";break;
					case 10 : echo "*gender belum dipilih";break;
					case 11 : echo "*gagal meng-upload file, silakan ulangi kembali";break;
					case 12 : echo "*username sudah terdaftar";break;
					case 13 : echo "*email sudah terdaftar";break;
				}
			}
		include("header.php");
?>
	<!-- Body -->
	<div id="bodycontent">
	  <div class="contentcontainer">
	    
		<div class="title-text">
		  <h1>Mendaftar</h1>
		</div>
		
		<div class="contentbox">
		<div class="error_message">
			<?php
				if(isset($_GET['err_msg']))
				{
					$err = explode("|",$_GET['err_msg']);
					foreach($err as $err_msg)
					{
						parseErrorMessage($err_msg);
						echo "<br/>";
					}
					
				}
			?>
			
		</div>
		<form method="POST" action="do_regis.php" enctype="multipart/form-data">
		  <div class="form-element1">Username:</div>
		  <div class="form-element2"><input type="text" name="username" size="35" <?php echo (isset($_GET['username']))? "value=".$_GET['username']:"";?> /></div>
		  <br/>
		  <div class="form-element1"></div>
		  <div class="form-element2"><small>(Minimal 5 karakter. Tidak boleh sama dengan password)</small></div>
		  <br/>
		  <div class="form-element1">Password:</div>
		  <div class="form-element2"><input type="password" name="password" size="20"/></div>
		  <br/>
		  <div class="form-element1"></div>
		  <div class="form-element2"><small>(Minimal 8 karakter. Tidak boleh sama dengan username atau email)</small></div>
		  <br/>
		  <div class="form-element1">Confirm Password:</div>
		  <div class="form-element2"><input type="password" name="confirm_password"  size="20"/></div>
		  <br/>
		  <div class="form-element1">Real Name:</div>
		  <div class="form-element2"><input type="text" name="real_name" size="35" value=<?php echo (isset($_GET['real_name']))? $_GET['real_name']:"\"\"";?> /></div>
		  <br/>
		  <div class="form-element1"></div>
		  <div class="form-element2"><small>(Minimal terdiri dari dua kata)</small></div>
		  <br/>
		  <div class="form-element1">Birthday:</div>
		  <div class="form-element2"><input type="text" name="birthday" size="35" value=<?php echo (isset($_GET['birthday']))? $_GET['birthday']:"\"\"";?> /></div>
		  <br/>
		  <div class="form-element1"></div>
		  <div class="form-element2"><small>(Format: YYYY-MM-DD)</small></div>
		  <br/>
		  <div class="form-element1">Email:</div>
		  <div class="form-element2"><input type="text" name="email" size="35" value=<?php echo (isset($_GET['email']))? $_GET['email']:"\"\"";?> /> </div>
		  <br/>
		  <div class="form-element1">Avatar:</div>
		  <div class="form-element2"><input type="file" name="avatar" size="35"/></div>
		  <br/>
		  <div class="form-element1"></div>
		  <div class="form-element2"><small>(Hanya .jpg atau .jpeg)</small></div>
		  <br/>
		  <div class="form-element1">Gender:</div>
		  <div class="form-element2">
		  <select name="sex">
			<option value="select_gender">Select Gender:</option>
			<option value="male">Male</option>
			<option value="female">Female</option>
		  </select>
	      </div>
		  <br/>
	      <div class="form-element1">About me (Optional):</div>
		  <br/>
		  <div class="form-element1"><textarea rows="5" cols="35" name="about" value=<?php echo (isset($_GET['about']))? $_GET['about']:"";?>></textarea></div>
		  <br/>
	      <div class="form-element1">
		  <input type="submit" id="register" value="Register"/>
		 </div>
		  <br/>
	      <div class="form-element1">Status:</div>
		  <div class="form-element2"><input type="text" name="status" size="35"/></div>
		  <br/>
		</div>
		</form>
	  </div>
	</div>

<?php
	}
	include("footer.php");
	include("close_con.php");
?>
